/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Forms;

import BusinessEntity.BE_CasoPruebaEstimacion;
import BusinessEntity.BE_Estimacion;
import BusinessEntity.BE_Personal;
import BusinessEntity.BE_Requerimiento;
import BusinessEntity.BE_Usuario;
import BusinessLogic.BL_Estimacion;
import BusinessLogic.BL_Requerimiento;
import Comun.Constantes;
import Comun.Funciones_Comunes;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JInternalFrame;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author richard.saldana
 */
public class Frm_Estimacion extends javax.swing.JInternalFrame {

    private JInternalFrame frmPadre;
        //tabla
    private DefaultTableModel objModelo;
    //Personal
    private BE_Personal objBEPersonal;
    //usuario
    private BE_Usuario objBEUsuario;
    //Requerimiento Seleccionado
    private BE_Requerimiento objBERequerimientoSeleccionado;
    //Opcion
    private int intOpcion;
    //lista Casos prueba
    public ArrayList<BE_CasoPruebaEstimacion> aobjBE_CasosPruebaEstimacion;
    /**
     * Creates new form Frm_Estimacion
     */
    public Frm_Estimacion(JInternalFrame frmVentana, int intCodigoRequerimiento, int intOpcion) throws InstantiationException, IllegalAccessException, SQLException {
        initComponents();
        setDefaultCloseOperation(0);
        this.frmPadre = frmVentana;
        this.objModelo = (DefaultTableModel) this.tblPruebas.getModel();
        this.objBEPersonal = ((Frm_BandejaTarea) this.frmPadre).getObjBEPersonal();
        this.objBEUsuario = ((Frm_BandejaTarea) this.frmPadre).getObjBEUsuario();
        this.aobjBE_CasosPruebaEstimacion = new ArrayList<BE_CasoPruebaEstimacion>();
        this.intOpcion = intOpcion;
        inicializar(intCodigoRequerimiento);
        
        cargarListaCasosPrueba();
        habilitarOpciones(this.objBEPersonal);
    }
    
       private void inicializar(int intCodigoRequerimiento) throws InstantiationException, IllegalAccessException, SQLException{
        
        this.objBERequerimientoSeleccionado = BL_Requerimiento.obtenerInstancia().obtenerRequerimientoID(intCodigoRequerimiento);
        txtCodigo.setText(Integer.toString(getObjBERequerimientoSeleccionado().getIdRequerimiento()));
        txtNombre.setText(getObjBERequerimientoSeleccionado().getStrNombre());
        jtxDescripcion.setText(getObjBERequerimientoSeleccionado().getStrDescripcion());
        
        if(this.intOpcion == Constantes.OpcionNuevo){
            //ocultamos columna 0
        this.tblPruebas.getColumnModel().getColumn(0).setMinWidth(0);
        this.tblPruebas.getColumnModel().getColumn(0).setMaxWidth(0);
        }
        
        /*
        //Datos de Combo segun la opcion
        setAobjBE_comboPersonal(BL_Personal.obtenerInstancia().obtenerPersonalAsignacion());
        if(this.aobjBE_comboPersonal != null){
            cmbPersonalAsig.removeAllItems();
            this.cmbPersonalAsig.addItem("<Seleccionar>");
            for (int i = 0; i < this.aobjBE_comboPersonal.size(); i++) {
                this.cmbPersonalAsig.addItem(this.aobjBE_comboPersonal.get(i));
                
            }
        }
        * */
        if(this.intOpcion == Constantes.OpcionModificar){
        /*
        BE_Personal objBE_Personal = new BE_Personal();
        objBE_Personal.setIdPersonal(this.objBERequerimientoSeleccionado.getIntUsuarioAsignado());
        this.cmbPersonalAsig.setSelectedItem(objBE_Personal);
        * */
        }
    }
       
           public void cargarListaCasosPrueba() throws InstantiationException, IllegalAccessException, SQLException {
        
         if (this.aobjBE_CasosPruebaEstimacion != null) {
            
            for (BE_CasoPruebaEstimacion objBE_CasoPruebaEstimacion : aobjBE_CasosPruebaEstimacion) {
              
                objModelo.addRow(new Object[]{
                          objBE_CasoPruebaEstimacion.getIdCasoPruebaEstimacion(),
                          objBE_CasoPruebaEstimacion.getStrNombre(),
                          objBE_CasoPruebaEstimacion.getObjBE_Sistema().getStrNombre(),
                          objBE_CasoPruebaEstimacion.getObjBE_Sistema().getObjSubsistema().getStrNombre()
                        });
            }
        }
       this.tblPruebas.updateUI();
        
        
    }
          
    public void calcularHoras(){
       
        int intAnalisis=0;
        int intDisenho=0;
        int intEjecucion=0;
        int intCierre=0;
        int intTotal = 0;
       
        if(!this.txtAnalisis.getText().equals("")){
            intAnalisis = Integer.parseInt(this.txtAnalisis.getText().toString());
        }
        
        if(!this.txtDisenho.getText().equals("")){
            intDisenho = Integer.parseInt(this.txtDisenho.getText().toString());
        }
        
        if(!this.txtEjecucion.getText().equals("")){
            intEjecucion = Integer.parseInt(this.txtEjecucion.getText().toString());
        }
        
        if(!this.txtCierre.getText().equals("")){
            intCierre = Integer.parseInt(this.txtCierre.getText().toString());
        }
        intTotal = intAnalisis + intDisenho + intEjecucion + intCierre;
        this.txtCantidadHoras.setText(String.valueOf(intTotal));
        
    }
    
     public void habilitarOpciones( BE_Personal objBEPersonal) throws InstantiationException, IllegalAccessException, SQLException {
        
      if(objBEPersonal.getObjBERol().getIdRol() == Constantes.Tester){

          this.btnEnviarEstimacion.setEnabled(true);
   
      }
     }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpaDetalle = new javax.swing.JPanel();
        lblCodigo = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        lblNombre = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtxDescripcion = new javax.swing.JTextArea();
        lblDescripcion = new javax.swing.JLabel();
        jpaEstimacion = new javax.swing.JPanel();
        lblCantidadHoras = new javax.swing.JLabel();
        txtCantidadHoras = new javax.swing.JTextField();
        txtCantidadRecursos = new javax.swing.JTextField();
        lblCantidadRecursos = new javax.swing.JLabel();
        lblAnalisis = new javax.swing.JLabel();
        lblDisenho = new javax.swing.JLabel();
        lblEjecucion = new javax.swing.JLabel();
        lblCierre = new javax.swing.JLabel();
        txtDisenho = new javax.swing.JTextField();
        txtAnalisis = new javax.swing.JTextField();
        txtEjecucion = new javax.swing.JTextField();
        jpaPruebas = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblPruebas = new javax.swing.JTable();
        btnAgregar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        lblPlanPruebas = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        txtPlanPruebas = new javax.swing.JTextField();
        jButton8 = new javax.swing.JButton();
        txtCierre = new javax.swing.JTextField();
        btnEnviarEstimacion = new javax.swing.JButton();
        btnReestimar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        jpaDetalle.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalle"));

        lblCodigo.setText("Código:");

        txtCodigo.setEnabled(false);

        lblNombre.setText("Nombre:");

        txtNombre.setEnabled(false);

        jtxDescripcion.setColumns(20);
        jtxDescripcion.setRows(5);
        jtxDescripcion.setEnabled(false);
        jScrollPane1.setViewportView(jtxDescripcion);

        lblDescripcion.setText("Descripción");

        javax.swing.GroupLayout jpaDetalleLayout = new javax.swing.GroupLayout(jpaDetalle);
        jpaDetalle.setLayout(jpaDetalleLayout);
        jpaDetalleLayout.setHorizontalGroup(
            jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpaDetalleLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpaDetalleLayout.createSequentialGroup()
                        .addComponent(jScrollPane1)
                        .addContainerGap())
                    .addGroup(jpaDetalleLayout.createSequentialGroup()
                        .addGroup(jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDescripcion)
                            .addGroup(jpaDetalleLayout.createSequentialGroup()
                                .addGroup(jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblNombre)
                                    .addComponent(lblCodigo))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                                    .addComponent(txtNombre))))
                        .addGap(60, 60, 60))))
        );
        jpaDetalleLayout.setVerticalGroup(
            jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpaDetalleLayout.createSequentialGroup()
                .addGroup(jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCodigo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpaDetalleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblDescripcion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(179, Short.MAX_VALUE))
        );

        jpaEstimacion.setBorder(javax.swing.BorderFactory.createTitledBorder("Estimación"));

        lblCantidadHoras.setText("Cantidad de horas:");

        txtCantidadHoras.setEnabled(false);

        txtCantidadRecursos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCantidadRecursosKeyTyped(evt);
            }
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCantidadRecursosKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtCantidadRecursosKeyReleased(evt);
            }
        });

        lblCantidadRecursos.setText("Cantidad de recursos:");

        lblAnalisis.setText("Análisis:");

        lblDisenho.setText("Diseño:");

        lblEjecucion.setText("Ejecución:");

        lblCierre.setText("Cierre:");

        txtDisenho.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDisenhoKeyTyped(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtDisenhoKeyReleased(evt);
            }
        });

        txtAnalisis.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtAnalisisKeyTyped(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtAnalisisKeyReleased(evt);
            }
        });

        txtEjecucion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtEjecucionKeyTyped(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtEjecucionKeyReleased(evt);
            }
        });

        jpaPruebas.setBorder(javax.swing.BorderFactory.createTitledBorder("Pruebas"));

        tblPruebas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nombre", "Sistema", "Subsistema"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(tblPruebas);

        btnAgregar.setText("Agregar");
        btnAgregar.setToolTipText("Agregar");
        btnAgregar.setActionCommand("");
        btnAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarActionPerformed(evt);
            }
        });

        btnEliminar.setText("Eliminar");
        btnEliminar.setToolTipText("Eliminar");
        btnEliminar.setActionCommand("");
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpaPruebasLayout = new javax.swing.GroupLayout(jpaPruebas);
        jpaPruebas.setLayout(jpaPruebasLayout);
        jpaPruebasLayout.setHorizontalGroup(
            jpaPruebasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpaPruebasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpaPruebasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4)
                    .addGroup(jpaPruebasLayout.createSequentialGroup()
                        .addComponent(btnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jpaPruebasLayout.setVerticalGroup(
            jpaPruebasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpaPruebasLayout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jpaPruebasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAgregar)
                    .addComponent(btnEliminar))
                .addGap(193, 193, 193))
        );

        lblPlanPruebas.setText("Plan de pruebas:");

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/find.gif"))); // NOI18N

        jButton8.setText("descargar");

        txtCierre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCierreKeyTyped(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtCierreKeyReleased(evt);
            }
        });

        btnEnviarEstimacion.setText("Enviar estimación");
        btnEnviarEstimacion.setActionCommand("");
        btnEnviarEstimacion.setEnabled(false);
        btnEnviarEstimacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEnviarEstimacionActionPerformed(evt);
            }
        });

        btnReestimar.setText("Reestimar");
        btnReestimar.setActionCommand("");
        btnReestimar.setEnabled(false);

        btnCancelar.setText("Cancelar");
        btnCancelar.setActionCommand("");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpaEstimacionLayout = new javax.swing.GroupLayout(jpaEstimacion);
        jpaEstimacion.setLayout(jpaEstimacionLayout);
        jpaEstimacionLayout.setHorizontalGroup(
            jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpaEstimacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpaEstimacionLayout.createSequentialGroup()
                        .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jpaEstimacionLayout.createSequentialGroup()
                                .addComponent(lblAnalisis)
                                .addGap(18, 18, 18)
                                .addComponent(txtAnalisis, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(lblDisenho)
                                .addGap(18, 18, 18)
                                .addComponent(txtDisenho, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jpaEstimacionLayout.createSequentialGroup()
                                .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblCantidadRecursos)
                                    .addComponent(lblCantidadHoras))
                                .addGap(18, 18, 18)
                                .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtCantidadHoras)
                                    .addComponent(txtCantidadRecursos, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addComponent(lblPlanPruebas)))
                        .addGap(18, 18, 18)
                        .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpaEstimacionLayout.createSequentialGroup()
                                .addComponent(txtPlanPruebas, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton8))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpaEstimacionLayout.createSequentialGroup()
                                .addComponent(lblEjecucion)
                                .addGap(18, 18, 18)
                                .addComponent(txtEjecucion, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(27, 27, 27)
                                .addComponent(lblCierre)
                                .addGap(18, 18, 18)
                                .addComponent(txtCierre, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 6, Short.MAX_VALUE))
                    .addComponent(jpaPruebas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpaEstimacionLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnEnviarEstimacion, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnReestimar, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jpaEstimacionLayout.setVerticalGroup(
            jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpaEstimacionLayout.createSequentialGroup()
                .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton7)
                    .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblCantidadHoras, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtCantidadHoras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblPlanPruebas, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtPlanPruebas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCantidadRecursos)
                    .addComponent(txtCantidadRecursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAnalisis)
                    .addComponent(lblDisenho)
                    .addComponent(txtAnalisis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEjecucion)
                    .addComponent(txtDisenho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEjecucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCierre)
                    .addComponent(txtCierre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jpaPruebas, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(jpaEstimacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnEnviarEstimacion)
                    .addComponent(btnCancelar)
                    .addComponent(btnReestimar))
                .addGap(29, 29, 29))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpaDetalle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpaEstimacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpaDetalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jpaEstimacion, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarActionPerformed
        Frm_CasoPrueba objFrm_CasoPrueba = null;
        try {
           
            objFrm_CasoPrueba = new Frm_CasoPrueba(this);
        } catch (InstantiationException ex) {
            Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
        }
        Frm_principal.jdpContenedor.add(objFrm_CasoPrueba);
        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension ventana = objFrm_CasoPrueba.getSize();
        objFrm_CasoPrueba.setLocation((pantalla.width - ventana.width) / 2, (pantalla.height - ventana.height) / 5);
        objFrm_CasoPrueba.toFront();
        objFrm_CasoPrueba.setVisible(true);
        this.limpiarGrilla();
        this.setVisible(false);
    }//GEN-LAST:event_btnAgregarActionPerformed

    private void txtCantidadRecursosKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadRecursosKeyTyped

        if (!(Funciones_Comunes.validaCadenaNumericaEntera(evt) && Funciones_Comunes.validaTamannoJText(evt, txtCantidadRecursos, 6))) {
            evt.consume();
        }
    }//GEN-LAST:event_txtCantidadRecursosKeyTyped

    private void txtAnalisisKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtAnalisisKeyTyped
        if (!(Funciones_Comunes.validaCadenaNumericaEntera(evt) && Funciones_Comunes.validaTamannoJText(evt, txtAnalisis, 6))) {
            evt.consume();
        }
    }//GEN-LAST:event_txtAnalisisKeyTyped

    private void txtDisenhoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDisenhoKeyTyped
        if (!(Funciones_Comunes.validaCadenaNumericaEntera(evt) && Funciones_Comunes.validaTamannoJText(evt, txtDisenho, 6))) {
            evt.consume();
        }
    }//GEN-LAST:event_txtDisenhoKeyTyped

    private void txtEjecucionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEjecucionKeyTyped
        if (!(Funciones_Comunes.validaCadenaNumericaEntera(evt) && Funciones_Comunes.validaTamannoJText(evt, txtEjecucion, 6))) {
            evt.consume();
        }
    }//GEN-LAST:event_txtEjecucionKeyTyped

    private void txtCierreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCierreKeyTyped
        if (!(Funciones_Comunes.validaCadenaNumericaEntera(evt) && Funciones_Comunes.validaTamannoJText(evt, txtCierre, 6))) {
            evt.consume();
        }
    }//GEN-LAST:event_txtCierreKeyTyped

    private void txtCantidadRecursosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadRecursosKeyPressed
        
    }//GEN-LAST:event_txtCantidadRecursosKeyPressed

    private void txtCantidadRecursosKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCantidadRecursosKeyReleased
        calcularHoras();
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCantidadRecursosKeyReleased

    private void txtAnalisisKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtAnalisisKeyReleased
        calcularHoras();
    }//GEN-LAST:event_txtAnalisisKeyReleased

    private void txtDisenhoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDisenhoKeyReleased
        calcularHoras();
    }//GEN-LAST:event_txtDisenhoKeyReleased

    private void txtEjecucionKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEjecucionKeyReleased
        calcularHoras();
    }//GEN-LAST:event_txtEjecucionKeyReleased

    private void txtCierreKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCierreKeyReleased
        calcularHoras();
    }//GEN-LAST:event_txtCierreKeyReleased

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        ((Frm_BandejaTarea) (this.frmPadre)).setVisible(true);
        ((Frm_BandejaTarea) (this.frmPadre)).tblRequerimientos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        try {
            ((Frm_BandejaTarea) (this.frmPadre)).cargarListaRequerimientos(this.objBEPersonal);
        } catch (InstantiationException ex) {
            Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        int intRowCount = tblPruebas.getSelectedRowCount();
        
       if(intRowCount > 1){
           Comun.GUI.msjAlerta("Solo se debe seleccionar un registro");
       }else if(intRowCount == 0){
           Comun.GUI.msjAlerta("Debe seleccionar un registro");
       }else{
           
           int intRow = tblPruebas.getSelectedRow();
                      
           ArrayList<BE_CasoPruebaEstimacion> aobjBE_CasoPruebaEstimacionActualizada = new ArrayList<BE_CasoPruebaEstimacion>();
       
           for (int i = 0; i < this.aobjBE_CasosPruebaEstimacion.size(); i++) {
               if(i!=intRow){
                   aobjBE_CasoPruebaEstimacionActualizada.add(this.aobjBE_CasosPruebaEstimacion.get(i));
               }
               
           }
           
           setAobjBE_CasosPruebaEstimacion(aobjBE_CasoPruebaEstimacionActualizada);
           this.tblPruebas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
           limpiarGrilla();
           
            try {
                cargarListaCasosPrueba();
            } catch (InstantiationException ex) {
                Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
            }
       
       }
        
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void btnEnviarEstimacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnviarEstimacionActionPerformed
        boolean bolCantidadHoras = (Funciones_Comunes.validarTextField(txtCantidadHoras.getText().trim(), "mayor", 0, lblCantidadHoras.getText()));
        boolean bolCantidadRecursos = (Funciones_Comunes.validarTextField(txtCantidadRecursos.getText().trim(), "mayor", 0, lblCantidadRecursos.getText()));
        boolean bolAnalisis= (Funciones_Comunes.validarTextField(txtAnalisis.getText().trim(), "mayor", 0, lblAnalisis.getText()));
        boolean bolDisenho = (Funciones_Comunes.validarTextField(txtDisenho.getText().trim(), "mayor", 0, lblDisenho.getText()));
        boolean bolEjecucion = (Funciones_Comunes.validarTextField(txtEjecucion.getText().trim(), "mayor", 0, lblEjecucion.getText()));
        boolean bolCierre = (Funciones_Comunes.validarTextField(txtCierre.getText().trim(), "mayor", 0, lblCierre.getText()));

 
        if(bolCantidadHoras && bolCantidadRecursos && bolAnalisis && bolDisenho && bolEjecucion && bolCierre){
          
            BE_Estimacion objBE_Estimacion = new BE_Estimacion();

          if(this.intOpcion == Constantes.OpcionNuevo){
              
            objBE_Estimacion = BL_Estimacion.obtenerInstancia().crearObjetoEstimacion(Integer.parseInt(txtCantidadHoras.getText().trim()), Integer.parseInt(txtCantidadRecursos.getText().trim()), Integer.parseInt(txtAnalisis.getText().trim()), Integer.parseInt(txtDisenho.getText().trim()), Integer.parseInt(txtEjecucion.getText().trim()), Integer.parseInt(txtCierre.getText().trim()), this.objBERequerimientoSeleccionado.getIdRequerimiento(), getAobjBE_CasosPruebaEstimacion());
               
          }else{
                //agregar logica para modificar
               /*objRequerimiento = BL_Requerimiento.obtenerInstancia().crearObjetoRequerimiento(txtNombre.getText().trim(),jtxDescripcion.getText().trim(), objPrioridad, getObjBEUsuario(), 0, this.objBERequerimientoSeleccionado.getIdRequerimiento());*/
          }
          
          
          if(this.intOpcion == Constantes.OpcionNuevo){
             try {
                if (Comun.GUI.msjPreguntaSiNo("¿Seguro que desea registrar su estimación?")) {
                        
                       BL_Estimacion.obtenerInstancia().registrarEstimacion(objBE_Estimacion);
                       Comun.GUI.msjAlerta("Se Registro la estimación Correctamente");                 
                }
                
                
                } catch (InstantiationException ex) {
                    Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
                }

                ((Frm_BandejaTarea) (this.frmPadre)).setVisible(true); 

               try {
                    ((Frm_BandejaTarea) (this.frmPadre)).cargarListaRequerimientos(this.objBEPersonal);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Frm_Estimacion.class.getName()).log(Level.SEVERE, null, ex);
                }
                this.dispose(); 
          }
          if(this.intOpcion == Constantes.OpcionModificar){
              /*
                try {
                    if (Comun.GUI.msjPreguntaSiNo("¿Seguro que desea modificar su Requerimiento?")) {
                           BL_Requerimiento.obtenerInstancia().modificarRequerimiento(objRequerimiento);
                           Comun.GUI.msjAlerta("Se modifico el Requerimiento Correctamente");                 
                }
                
                
                } catch (InstantiationException ex) {
                    Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                 ((Frm_BandejaTarea) (this.frmPadre)).setVisible(true); 

               try {
                    ((Frm_BandejaTarea) (this.frmPadre)).cargarListaRequerimientos(this.objBEPersonal);
                } catch (InstantiationException ex) {
                    Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                    Logger.getLogger(Frm_Requerimiento.class.getName()).log(Level.SEVERE, null, ex);
                }
                this.dispose(); 
                */
          }
          
        }
    }//GEN-LAST:event_btnEnviarEstimacionActionPerformed

        public void limpiarGrilla() {
       this.objModelo.getDataVector().removeAllElements();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnEnviarEstimacion;
    private javax.swing.JButton btnReestimar;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JPanel jpaDetalle;
    private javax.swing.JPanel jpaEstimacion;
    private javax.swing.JPanel jpaPruebas;
    private javax.swing.JTextArea jtxDescripcion;
    private javax.swing.JLabel lblAnalisis;
    private javax.swing.JLabel lblCantidadHoras;
    private javax.swing.JLabel lblCantidadRecursos;
    private javax.swing.JLabel lblCierre;
    private javax.swing.JLabel lblCodigo;
    private javax.swing.JLabel lblDescripcion;
    private javax.swing.JLabel lblDisenho;
    private javax.swing.JLabel lblEjecucion;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblPlanPruebas;
    public javax.swing.JTable tblPruebas;
    private javax.swing.JTextField txtAnalisis;
    private javax.swing.JTextField txtCantidadHoras;
    private javax.swing.JTextField txtCantidadRecursos;
    private javax.swing.JTextField txtCierre;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDisenho;
    private javax.swing.JTextField txtEjecucion;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtPlanPruebas;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the objBEPersonal
     */
    public BE_Personal getObjBEPersonal() {
        return objBEPersonal;
    }

    /**
     * @param objBEPersonal the objBEPersonal to set
     */
    public void setObjBEPersonal(BE_Personal objBEPersonal) {
        this.objBEPersonal = objBEPersonal;
    }

    /**
     * @return the objBEUsuario
     */
    public BE_Usuario getObjBEUsuario() {
        return objBEUsuario;
    }

    /**
     * @param objBEUsuario the objBEUsuario to set
     */
    public void setObjBEUsuario(BE_Usuario objBEUsuario) {
        this.objBEUsuario = objBEUsuario;
    }

    /**
     * @return the objBERequerimientoSeleccionado
     */
    public BE_Requerimiento getObjBERequerimientoSeleccionado() {
        return objBERequerimientoSeleccionado;
    }

    /**
     * @param objBERequerimientoSeleccionado the objBERequerimientoSeleccionado to set
     */
    public void setObjBERequerimientoSeleccionado(BE_Requerimiento objBERequerimientoSeleccionado) {
        this.objBERequerimientoSeleccionado = objBERequerimientoSeleccionado;
    }

    /**
     * @return the intOpcion
     */
    public int getIntOpcion() {
        return intOpcion;
    }

    /**
     * @param intOpcion the intOpcion to set
     */
    public void setIntOpcion(int intOpcion) {
        this.intOpcion = intOpcion;
    }

    /**
     * @return the aobjBE_CasosPruebaEstimacion
     */
    public ArrayList<BE_CasoPruebaEstimacion> getAobjBE_CasosPruebaEstimacion() {
        return aobjBE_CasosPruebaEstimacion;
    }

    /**
     * @param aobjBE_CasosPruebaEstimacion the aobjBE_CasosPruebaEstimacion to set
     */
    public void setAobjBE_CasosPruebaEstimacion(ArrayList<BE_CasoPruebaEstimacion> aobjBE_CasosPruebaEstimacion) {
        this.aobjBE_CasosPruebaEstimacion = aobjBE_CasosPruebaEstimacion;
    }
}
